package com.wanmait.movie.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.wanmait.movie.entity.Comments;
import com.wanmait.movie.entity.Movie;
import com.wanmait.movie.entity.Reply;
import com.wanmait.movie.entity.User;
import com.wanmait.movie.entity.VO.ReplyVO;
import com.wanmait.movie.mapper.ReplyMapper;
import com.wanmait.movie.service.ReplyService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
public class ReplyServiceImpl extends ServiceImpl<ReplyMapper, Reply>implements ReplyService {
    @Resource
    private ReplyMapper replyMapper;
    @Override
    public PageInfo<Reply> getReplyList(int pageNum, int commentsId, String keyword) {

        PageHelper.startPage(pageNum, 10);
        MPJLambdaWrapper<Reply> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(Reply.class)
                .select(User::getUsername)
                .leftJoin(User.class, User::getId, Reply::getReplyUserId);
//        queryWrapper.orderByDesc(Reply::getCommentsId);
        if (commentsId != 0){
            queryWrapper.eq(Reply::getCommentsId, commentsId);
        }
        if (keyword!=""){
            queryWrapper.like(Reply::getReply,keyword);
            queryWrapper.or().like(User::getUsername,keyword);
        }
        List<ReplyVO> replies = replyMapper.selectJoinList(ReplyVO.class,queryWrapper);
        return new PageInfo(replies);
    }

    @Override
    public List<Reply> getList() {
        return null;
    }
}
